/**
 * 判断元素是否有echart实例
 * 有就销毁
 * 如果已经销毁不管
 */
import {BaseParams} from "./types";

export function ElHasEchartDecorator(): MethodDecorator {
  return function (target: object, name: string | symbol, descriptor: TypedPropertyDescriptor<any>) {
    const oldFunc = descriptor.value
    descriptor.value = function (...args) {
      const params = args[0] as BaseParams
      if (params.el.__echart) {
        if (!params.el.__echart.isDisposed()) {
          params.el.__echart.dispose()
        }
      }
      params.el.__echart = oldFunc.apply(this, args)
      return params.el.__echart
    }
  }
}
